<?php
class createConnection
{
    var $host="localhost";
    var $username="root";    // specify the sever details for mysql
    Var $password="";
    var $database="obstacle_db";
    var $myconn;

    /**
     * This function makes a connection to the mysql-database
     */
    function connectToDatabase()
    {
        $conn= mysql_connect($this->host,$this->username,$this->password,false,65536);
        mysql_set_charset('utf8',$conn);
        
        if(!$conn)// testing the connection
        {
            die ("Cannot connect to the database");
        }
        else
        {
            $this->myconn = $conn;
        }

        return $this->myconn;
    }

    /**
     * This function connects to the database we need from the mysql-database
     */
    function selectDatabase()
    {
        mysql_select_db($this->database);

        if(mysql_error())
        {
            echo "Cannot find the database ".$this->database;
        }
    }

    /**
     * This function closes the connection to the mysql-database
     */
    function closeConnection()
    {
        mysql_close($this->myconn);
    }
}
?>